// Copyright 2019 The rhyme_lph Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// j [author] rhyme_lph
// Y [email]  rhymelph@gmail.com
// a [github] https://github.com/rhymelph

import 'package:base_plugin/base_plugin.dart';
import 'package:finance_app/generated/l10n.dart';
import 'package:finance_app/src/common/app_colors.dart';
import 'package:finance_app/src/common/app_spaces.dart';
import 'package:finance_app/src/widgets/button/choose_button.dart';
import 'package:flutter/material.dart';
import 'package:finance_app/src/provider/system_detection_provider.dart';
import 'package:finance_app/src/router_gen/router_meta.dart';

@RouterMeta(paramName: "systemDetectionPage")
class SystemDetectionPage extends StatefulWidget {
  @override
  _SystemDetectionPageState createState() => _SystemDetectionPageState();
}

class _SystemDetectionPageState extends State<SystemDetectionPage>
    with PagePresenter<SystemDetectionPage, SystemDetectionProvider> {
  @override
  Widget get buildWidget => Scaffold(
        body: ListView(
          padding: EdgeInsets.zero,
          children: [
            _buildTopBar(),
            AppSpaces.h40,
            listBuilder<int>(
                builder: (BuildContext context, int value, Widget child) =>
                    Column(
                      children: value == 0 ? firstPage() : secondPage(),
                    ),
                selector: (_, __) => __.step),
          ],
        ),
      );

  List<Widget> secondPage() => [
        _buildTipText(
          tip: S.current.number_of_invitations,
        ),
        AppSpaces.h18,
        ChooseButton(
          text: '1 invitation',
          onTap: provider.onChoose,
        ),
        AppSpaces.h18,
        ChooseButton(
          text: S.current.more_than_1_invitation,
          onTap: provider.onChoose,
        )
      ];

  List<Widget> firstPage() => [
        _buildTipText(
          tip: S.current.if_number_belongs_to,
        ),
        AppSpaces.h18,
        ChooseButton(
          text: S.current.company_staff___with_invitation,
          onTap: provider.onChoose,
        ),
        AppSpaces.h18,
        ChooseButton(
          text: S.current.no_invitation___associated,
          onTap: provider.onChoose,
        )
      ];

  Center _buildTipText({String tip}) {
    return Center(
      child: Text(
        tip,
        style: TextStyle(
          color: aceBlackColor,
          fontSize: getSp(20),
          fontWeight: FontWeight.bold,
        ),
      ),
    );
  }

  Widget _buildTopBar() {
    return Container(
      color: aceBlueColor,
      height: getDp(132),
      padding: EdgeInsets.only(
        top: MediaQuery.of(context).padding.top,
      ),
      alignment: Alignment.center,
      child: Text(
        S.current.system_detection,
        style: TextStyle(
          color: Colors.white,
          fontSize: getSp(28),
          fontWeight: FontWeight.bold,
        ),
      ),
    );
  }
}
